//
//  UserModel.m
//  QGZone
//
//  Created by xiabin on 15/8/11.
//  Copyright (c) 2015年 Olive.Banana. All rights reserved.
//

#import "UserModel.h"
#import "ServerCodecDef.h"

@implementation UserModel


+(id)modelWithRegDict:(NSDictionary *)dict
{
    UserModel *user = [[self alloc] init];
    user.nickname = [Utils StringValueForDict:dict ForKey:kUserNick];
    if ([user.nickname length]==0) {
     user.nickname = @"格客";
    }
    user.gender = [dict[kUserGender] intValue];
    user.avatar = [Utils StringValueForDict:dict ForKey:kUserAvatarUrl];
    user.uid = [dict[kUserUID] intValue];
    user.signature = dict[kUserSig];
    if (!user.signature) user.signature = @" ";
    return user;
}

+(id)modelwithQQInfo:(NSDictionary *)dict {
    UserModel *user = [[self alloc] init];
    user.nickname = [Utils StringValueForDict:dict ForKey:kQQNick];
    if ([user.nickname length]==0) {
        user.nickname = @"格客";
    }
    NSString* gender = [Utils StringValueForDict:dict ForKey:kQQGender];
    if ([gender compare:@"男"] == NSOrderedSame) {
        user.gender = 1;
    } else {
        user.gender = 2;
    }
    user.avatar = [Utils StringValueForDict:dict ForKey:kQQAvatar];
    return user;
}

+(id)modelwithWechatInfo:(NSDictionary *)dict {
    UserModel *user = [[self alloc] init];
    user.nickname = [Utils StringValueForDict:dict ForKey:kWechatNick];
    if ([user.nickname length]==0) {
        user.nickname = @"格客";
    }
    user.gender = [dict[kWechatGender] intValue];
    user.avatar = [Utils StringValueForDict:dict ForKey:kWechatAvater];
    return user;
}

+(id)modelWithNormalDict:(NSDictionary *)dict
{
    UserModel *user = [[self alloc] init];
    user.nickname = [Utils StringValueForDict:dict ForKey:kUserNick];
    if ([user.nickname length] == 0) {
        user.nickname = @"格客";
    }
    user.gender = [dict[kUserGender] intValue];
    user.avatar = [Utils StringValueForDict:dict ForKey:kUserAvatarUrl];
    user.uid = [dict[kUserUID] intValue];
    user.company = [Utils StringValueForDict:dict ForKey:kUserCompany];
    user.signature = [Utils StringValueForDict:dict ForKey:kUserSig];
    user.strbirthday = [Utils StringValueForDict:dict ForKey:kUserBirthday];
    user.followStatus = [dict[kUserFollowed] intValue];
    
    if ([Utils Dictionary:dict ContainsNormalKey:kAddressRegionId]) {
        user.hometownId = [dict[kAddressRegionId] intValue];
    }
    if ([Utils Dictionary:dict ContainsNormalKey:kUserHometownId]) {
        user.hometownId = [dict[kUserHometownId] intValue];
    }
    if ([Utils Dictionary:dict ContainsNormalKey:kUserFollowed]) {
        user.liked = ![dict[kUserFollowed] intValue];
    }
    return user;
}

-(NSDictionary*)toDictionary
{
    NSMutableDictionary *tmpDic = [[NSMutableDictionary alloc] init];
    [tmpDic setObject:[NSNumber numberWithInt:_uid] forKey:kUserUID];
    [tmpDic setObject:_avatar forKey:kUserAvatarUrl];
    [tmpDic setObject:_nickname forKey:kUserNick];
    [tmpDic setObject:[NSNumber numberWithInt:_gender] forKey:kUserGender];
    if(_signature != nil) [tmpDic setObject:_signature forKey:kUserSig];
    if(_company != nil) [tmpDic setObject:_company forKey:kUserCompany];
    [tmpDic setObject:[NSNumber numberWithInt:_followCnt] forKey:kUserfollowerCnt];
    [tmpDic setObject:[NSNumber numberWithInt:_followingCnt] forKey:kUserfollowingCnt];
    if(_hometownId != 0) {
        [tmpDic setObject:[NSNumber numberWithInt:_hometownId] forKey:kAddressRegionId];
    }
    return tmpDic;
}

@end
